const path = require('path');
const htmlPlugin = require('html-webpack-plugin')
const { CleanPlugin } = require('webpack');
console.log("-----NODE_ENV-----:" + process.env.NODE_ENV)
const mode=process.env.NODE_ENV === 'dev' ? 'development' : 'production';

module.exports = {
    entry: {
        'main': path.resolve('src/ourrecord.js'),
    },
    output: {
        path: path.resolve('dist'),
        filename: '[name].[contenthash].js'
    },
    resolve: {
        extensions: ['.js', '.jsx'],
        alias: {
            '~': path.resolve(__dirname, 'src')
        }
    },
    module: {
        rules: [
            { 
                test: /\.(js|jsx)$/, 
                exclude: /node_modules/, 
                loader: "babel-loader",
                options: {
                    presets: ['@babel/preset-env', '@babel/preset-react'],
                    plugins: ['@babel/plugin-proposal-class-properties']
                }
            },
            {
                test: /\.(css|scss)$/,
                exclude: /node_modules/,
                use: [
                    'style-loader',
                    'css-loader',
                    'sass-loader'
                ]
            }
        ]
    },
    plugins: [
        new htmlPlugin({
            template: path.resolve('index.html'),
        }),
        new CleanPlugin(),

    ],
    mode: mode,
}